<template>
  <section class="content" style="position: relative;">

    <!-- row -->
    <div class="row">
      <div class="col-md-12">
        <!-- The time line -->
        <ul class="timeline">
          <!-- timeline item -->
          <li>
            <div class="timeline-item">

              <h3 class="timeline-header"><a href="#">基本信息</a></h3>

              <div class="timeline-body">
                <div class="form-horizontal clearfix">
                  <div class="col-sm-8">
                    <div class="form-group">
                      <div class="col-sm-12">
                        <label for="" class="control-label"><sup class="text-red">*</sup> 组合SKU：</label>
                        <div class="">
                          <input type="text" class="form-control col-sm-9" :disabled="readonly" placeholder="长度不超过50位，只能字母、数字、-、_" v-model="combination.sku">
                        </div>
                      </div>
                    </div>
                    <div class="form-group">
                      <div class="col-sm-12">
                        <label for="" class="control-label"><sup class="text-red">*</sup> 中文名称：</label>
                        <div class="">
                          <input type="text" class="form-control col-sm-9" placeholder="长度不超过100" :disabled="readonly" v-model="combination.goodsCn">
                        </div>
                      </div>
                    </div>
                    <div class="form-group">
                      <div class="col-sm-12">
                        <label for="" class="control-label"><sup class="text-red">*</sup> 英文名称：</label>
                        <div class="">
                          <input type="text" class="form-control col-sm-9" :disabled="readonly" placeholder="长度不超过100" v-model="combination.goodsEn">
                        </div>
                      </div>
                    </div>
                    <div class="form-group">
                      <div class="col-sm-12">
                        <label for="" class="control-label">商品分类：</label>
                        <div class="" v-if="allCategoryAnalysis.length != 0" style="position: relative;">
                          <el-input
                            placeholder="请选择商品分类"
                            v-model="formData.inspectObjectName"
                            icon="caret-bottom"
                            suffix-icon="el-icon-arrow-down"
                            readonly="readonly"
                            class="linehe"
                            :disabled="readonly"
                            @click.native="isShowSelectFn">
                          </el-input>
                          <el-tree v-if="isShowSelect"
                                   empty-text="暂无数据"
                                   :expand-on-click-node="false"
                                   :data="allCategoryAnalysis"
                                   :props="defaultProps"
                                   default-expand-all
                                   @node-click="handleNodeClick"
                                   class="objectTree">
                          </el-tree>
                          <!--<select class="form-control" v-model="combination.categoryId" :disabled="readonly">-->
                            <!--<option value="">请选择分类</option>-->
                            <!--<option :value="classificationListItem.id" v-for="classificationListItem in classificationList">{{classificationListItem.name}}</option>-->
                          <!--</select>-->
                          <!--<select class="form-control" v-model="combination.categoryId" :disabled="readonly">-->
                            <!--<option value="">请选择商品分类</option>-->
                            <!--<optgroup :label="allCategoryAnalysisItem.categoryName" v-for="allCategoryAnalysisItem in allCategoryAnalysis">-->
                              <!--{{allCategoryAnalysisItem.categoryName}}-->
                              <!--<option v-for="productSelectItem in allCategoryAnalysisItem.children" :value="productSelectItem.categoryId">-->
                                <!--{{productSelectItem.categoryName}}-->
                              <!--</option>-->
                            <!--</optgroup>-->

                          <!--</select>-->
                          <router-link v-if="!readonly && allCategoryAnalysis.length != 0" to="/v1/goods/category/getList" class="addProductCate">添加商品分类</router-link>
                        </div>
                        <div class="" v-else>
                          <label class="payment">
                            <i class="fa fa-warning"></i>
                            您当前还未添加商品分类
                            <router-link to="/v1/goods/category/getList" class="text-red text-bold">【立即添加】</router-link>
                          </label>
                        </div>
                      </div>
                    </div>
                    <div class="form-group">
                      <div class="col-sm-12">
                        <label for="" class="control-label">商品图片：</label>
                        <div>
                          <div class="row col-sm-5">
                            <div class="border-default">
                              <div class="maxImg">
                                <img v-if="picShow" src="@/assets/addPic.png" alt="">
                                <img class="pic" v-else :src="combination.goodsPic" alt="">
                                <img class="delPic" v-if="!picShow && !readonly" src="@/assets/delete.png" alt="" @click="deletePicConfirm">
                              </div>
                              <div>
                                <input @change="choosePic($event)" type="file" style="display: none" id="file-upload" accept="image/jpg,image/jpeg,image/png,image/gif">
                                <a @click="fileClick()" v-if="!readonly" class="btn btn-info m-t-15">上传图片</a>
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                    <div class="form-group">
                      <div class="col-sm-12">
                        <label for="" class="control-label">品牌：</label>
                        <div class="" v-if="brandList.length != 0">
                          <select class="form-control" v-model="combination.brandId" :disabled="readonly">
                            <option value="">请选择分类</option>
                            <option :value="brandListItem.id" v-for="brandListItem in brandList">{{brandListItem.brandName}}</option>
                          </select>
                          <router-link v-if="!readonly && brandList.length != 0" to="/v1/goods/brand/getList" class="addProductCate">添加品牌分类</router-link>
                        </div>
                        <div class="" v-else>
                          <label class="payment">
                            <i class="fa fa-warning"></i>
                            您当前还未添加商品分类
                            <router-link to="/v1/goods/category/getList" class="text-red text-bold">【立即添加】</router-link>
                          </label>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
              <!--<div class="timeline-footer">-->
                <!--<a class="btn btn-primary btn-xs">Read more</a>-->
                <!--<a class="btn btn-danger btn-xs">Delete</a>-->
              <!--</div>-->
            </div>
          </li>
          <!-- END timeline item -->
          <!-- timeline item -->
          <li>
            <div class="timeline-item">

              <h3 class="timeline-header"><a href="#">组合信息</a></h3>

              <div class="timeline-body">
                <div class="" v-if="!readonly">
                  <button data-toggle="modal" data-target="#modal-default1" class="btn btn-primary m-b-20" @click="getProductList(0)">添加产品
                  </button>
                </div>

                <div class="">
                  <table class="table table-bordered table-hover">
                    <thead>
                    <tr>
                      <th style="width: 15%">商品图片</th>
                      <th>商品信息</th>
                      <th style="width: 10%">单位个数</th>
                      <th v-if="!readonly" style="width: 10%">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr v-if="combination.goodsInfoList.length == 0">
                      <td colspan="5">
                        没有数据
                      </td>
                    </tr>
                    <tr v-else v-for="(productCombinItem,index) in combination.goodsInfoList">
                      <td>
                        <img v-if="productCombinItem.goodsPic" :src="productCombinItem.goodsPic" alt="">
                        <img v-else src="@/assets/noPic.png" alt="">
                      </td>
                      <td class="text-left">
                        <label class="m-l-15">
                          <p>
                            <label>货号：</label>
                            <span>{{productCombinItem.sku}}</span>
                          </p>
                          <p>
                            <label>品名：</label>
                            <span>{{productCombinItem.goodsCn}}</span>
                          </p>
                          <p>
                            <label>品牌：</label>
                            <span>{{productCombinItem.brandName}}</span>
                          </p>
                        </label>
                      </td>
                      <td>
                        <input type="text" class="form-control" :disabled="readonly" v-model="productCombinItem.quantity">
                      </td>
                      <td v-if="!readonly">
                        <a class="text-green" @click="deleteComfrim(index)">删除</a>
                      </td>
                    </tr>
                    </tbody>
                  </table>
                </div>
              </div>
              <div class="timeline-footer text-center">
                <a class="btn btn-primary m-lr-10" v-if="!readonly" @click="submitProduct">保存商品</a>
                <router-link to="/v1/goods/combination/getList" class="btn btn-default m-lr-10">返 回</router-link>
              </div>
            </div>
          </li>
        </ul>
      </div>
      <!-- /.col -->
    </div>

    <div class="modal fade" id="modal-default1">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title">选择商品</h4>
          </div>
          <div class="modal-body">
            <div class="form-horizontal">
              <div class="box-body">
                <div class="form-group">
                  <div class="col-sm-12 clearfix flex">
                    <label for="" class="control-label bg-gray min-width">输入搜索：</label>
                    <input type="text" class="form-control pull-left" style="width: 350px" placeholder="请输入商品名称或商品货号" v-model="productName">
                    <button class="btn btn-success m-lr-10 pull-left" @click="searchProduct">搜&nbsp;索</button>
                    <button class="btn btn-danger m-lr-10 pull-left" @click="resetProduct">重&nbsp;置</button>
                  </div>
                </div>
                <div class="form-group">
                  <label for="" class="col-sm-12">
                    <!--<button type="button" class="btn btn-success pull-left m-r-10" data-toggle="modal" data-target="#modal-default">创建调拨单</button>-->
                  </label>
                </div>
                <div class="form-group">
                  <div class="col-sm-12">
                    <table id="example5" class="table table-bordered table-hover marginNonde">
                      <thead>
                      <tr>
                        <th>
                          <label>
                            <input type="checkbox" class="flat-red" v-model="allProduct" @change="checkAllProduct">
                          </label>
                        </th>
                        <th>商品信息</th>
                        <th>库存总量</th>
                      </tr>
                      </thead>
                      <tbody>
                      <tr v-for="(productListItem,index) in productList">
                        <td>
                          <label>
                            <input type="checkbox" class="flat-red" :value="productListItem"
                                   v-model="checkedProduct">
                          </label>
                        </td>
                        <td class="text-left">
                          <img v-if="productListItem.goodsPic" :src="productListItem.goodsPic" alt="">
                          <img v-else src="@/assets/noPic.png" alt="">
                          <label class="m-l-15">
                            <p>
                              <label>货号：</label>
                              <span>{{productListItem.sku}}</span>
                            </p>
                            <p>
                              <label>品名：</label>
                              <span>{{productListItem.goodsCn}}</span>
                            </p>
                            <p>
                              <label>品牌：</label>
                              <span>{{productListItem.brandName}}</span>
                            </p>
                          </label>
                        </td>
                        <td>
                          {{productListItem.stockQty ? productListItem.stockQty : 0}}
                        </td>
                      </tr>
                      </tbody>
                    </table>
                    <div class="clearfix">
                      <div class="m-t-15 pull-right">
                        <pagination :total="pages.productList.total" :current-page='pages.productList.pageNum'
                                    :display="pages.productList.display" @pagechange="pagechange"></pagination>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="modal-footer">
            <button v-if="checkedProduct.length >= 0 && !readonly" type="button" class="btn btn-primary" data-dismiss="modal"
                    data-toggle="modal"  data-target="#modal-default2" @click="addProductSubmit">保存
            </button>
            <button type="button" class="btn btn-default" data-dismiss="modal" data-toggle="modal"
                    data-target="#modal-default2">返 回
            </button>
          </div>
        </div>
        <!-- /.modal-content -->
      </div>
      <!-- /.modal-dialog -->
    </div>

    <transition name="fade">
      <div v-if="errorShow" class="gritter-notice-wrapper " :class="{'success-notice-wrapper':errorClass}">
        <div id="gritter-item-4" class="gritter-item-wrapper gritter-error" style="" role="alert">
          <div class="gritter-item"><a class="gritter-close" tabindex="1" @click="closeError"><i
            class="fa fa-close"></i></a>
            <div class="gritter-without-image"><span class="gritter-title">{{errorTitle}}</span>
              <p>{{errorMsg}}</p></div>
          </div>
        </div>
      </div>
    </transition>
    <div class="treeSelect" v-if="isShowSelect" @click.self.prevent="isShowSelect = false"></div>
  </section>
</template>

<script>
  import '@/assets/taginput/jquery.tagsinput.css'
  import '@/assets/taginput/jquery.tagsinput'
  import pagination from '@/components/common/pageComponent'
  import baseURL from '@/js/common/baseURL'
  import axios from 'axios'
  import instance from '@/api/index.js'

  export default {
    name: "combinationSKU",
    data() {
      return {
        imgList: [],
        size: 0,
        pages:{
          productList:{
            total:0,
            pageNum:1,
            display:10,
          }
        },
        checkedProduct:[],
        singleSKU:{
          goodsCn:''
        },
        productList:[],//商品数据
        productListParmas:{},//添加产品传参
        productCombin:[],//选择组合商品
        errorShow: false,//错误显示
        errorMsg: '',//错误信息
        errorTitle: '',//错误提示标题
        errorClass: false,//错误样式
        show:true,
        allProduct:'',//全选
        allProductList:[],
        picShow:true,
        combination:{
          id: null,
          goodsCn: "",
          goodsEn: "",
          sku: "",
          categoryId: '',
          brandId: '',
          goodsPic: null,
          goodsInfoList:[]
        },

        allCategoryAnalysis:[],//商品分类
        allCategory:[],
        classificationList:[],
        productName:'',
        brandList:[],
        readonly:false,
        formData: {
          // 传给后台的id
          inspectObject: "",
          // 输入框显示的
          inspectObjectName: ""
        },
        // 是否显示巡检对象的树状选择器
        isShowSelect: false,
        // 巡检对象的选项数据
        inspectionObjectOptions: [],
        // 巡检对象的选项的配置参数
        defaultProps: {
          id: "categoryId",
          label: 'categoryName',
          children: 'children'
        },
        allMenu:[],
      }
    },
    methods: {
      isShowSelectFn:function(){
        if (!this.readonly){
          this.isShowSelect = !this.isShowSelect;
        }
      },
      handleNodeClick(data, Node) {
        // 如果是顶级父节点
        this.formData.inspectObjectName = data.categoryName;
        this.combination.categoryId = data.categoryId;
        // 关闭选择器
        this.isShowSelect = false;
      },
      // 获取分页
      pagechange: function (currentPage) {
        this.pages.productList.pageNum = currentPage;
        this.productListParmas.page = currentPage;
        this.getProductList(1);
      },

      //获取添加产品数据
      getProductList:function(type){
        let vm = this;
        if(type == 0){
          vm.checkedProduct = [];
        }
        vm.allProduct = false;
        vm.productListParmas.rows = 5;
        vm.productName = '';
        vm.productListParmas.name = vm.productName;
        vm.pages.productList.display = vm.productListParmas.rows;
        instance({
          method:'post',
          url:'v1/goods/getList',
          params:vm.productListParmas
        }).then(function (data) {
          if(data.data.success){
            vm.productList = data.data.data.list;
            vm.pages.productList.total = data.data.data.total;
            console.log(data)
          }
        })
      },

      //获取所有商品分类树
      getAllCategory: function () {
        let vm = this;
        instance({
          method: 'post',
          url: '/v1/goods/category/getAll',
        }).then(function (data) {
          if (data.data.success) {
            let menus = data.data.data;
            vm.allMenu = menus;
            console.log(vm.allMenu)
            vm.menuListCheck = [];
            vm.getData(null,menus);
            vm.depositMenus = [];
            for (let i = 0; i < vm.menuListCheck.length; i++){
              if(vm.menuListCheck[i].categoryParentId == null){
                vm.depositMenus.push(vm.menuListCheck[i])
              }
            }
            vm.allCategoryAnalysis = vm.depositMenus;
          }
          console.log('vm.allCategoryAnalysis',vm.allCategoryAnalysis)
          //
          // vm.classificationListL2 = vm.allCategoryAnalysis
        })
      },

      getData: function (id, arry) {
        let vm = this;
        var childArry = this.familyTree(id, arry);
        if (childArry.length > 0) {
          for (var i = 0; i < childArry.length; i++) {
            let obj = {};
            obj = childArry[i];
            childArry[i].children = this.familyTree(childArry[i].categoryId, arry);
            childArry[i].show = false;
            vm.menuListCheck.push(obj);
            vm.getData(childArry[i].categoryId, arry);
          }
        }
      },
      //
      familyTree: function (id, arry) {
        var newArry = new Array();
        for (var i in arry) {
          if (arry[i].categoryParentId == id)
            newArry.push(arry[i]);
        }
        return newArry;
      },

      //搜索商品
      searchProduct:function(){
        let vm = this;
        vm.productListParmas.name = vm.productName;
        vm.pages.productList.pageNum = 1;
        vm.allProduct = false;
        vm.productListParmas.rows = 5;
        vm.pages.productList.display = vm.productListParmas.rows;
        instance({
          method:'post',
          url:'v1/goods/getList',
          params:vm.productListParmas
        }).then(function (data) {
          if(data.data.success){
            vm.productList = data.data.data.list;
            vm.pages.productList.total = data.data.data.total;
            console.log(data)
          }
        })
      },

      //重置
      resetProduct:function(){
        this.productListParmas.name = '';
        this.productName = '';
        this.pages.productList.pageNum = 1;
        let vm = this;
        vm.allProduct = false;
        vm.productListParmas.rows = 5;
        vm.pages.productList.display = vm.productListParmas.rows;
        instance({
          method:'post',
          url:'v1/goods/getList',
          params:vm.productListParmas
        }).then(function (data) {
          if(data.data.success){
            vm.productList = data.data.data.list;
            vm.pages.productList.total = data.data.data.total;
            console.log(data)
          }
        })
      },

      //保存
      addProductSubmit:function(){
        let vm = this;
        if(this.checkedProduct.length <= 0){
          // this.errorClass = false;
          // this.errorShow = true;
          // this.errorTitle = "操作失败";
          // this.errorMsg = "商品列表至少需要两个商品";
          // this.setTime();
          this.$message.error('商品列表至少需要两个商品');
        }else {
            if(vm.combination.goodsInfoList != 0){
              for (let i = 0; i < vm.checkedProduct.length; i++){
                let obj = {};
                obj.sku = vm.checkedProduct[i].sku;
                obj.goodsCn = vm.checkedProduct[i].goodsCn;
                obj.goodsEn = vm.checkedProduct[i].goodsEn;
                obj.categoryId = vm.checkedProduct[i].categoryId;
                obj.brandId = vm.checkedProduct[i].brandId;
                obj.goodsPic = vm.checkedProduct[i].goodsPic;
                obj.brandName = vm.checkedProduct[i].brandName;
                obj.quantity = vm.checkedProduct[i].quantity;
                let matchTag = true;
                for(let m = 0; m < vm.combination.goodsInfoList.length; m++){
                  let current = vm.combination.goodsInfoList[m];
                  if(current){
                    if(vm.checkedProduct[i]['sku'] == current['sku']){
                      matchTag = false;
                      break;
                    }
                  }else {
                    matchTag = false;
                  }
                }
                if(matchTag){
                  vm.combination.goodsInfoList.push(obj);
                }
              }
            }else {
              for (let ii = 0; ii < vm.checkedProduct.length; ii++) {
                let obj = {};
                obj.sku = vm.checkedProduct[ii].sku;
                obj.goodsCn = vm.checkedProduct[ii].goodsCn;
                obj.goodsEn = vm.checkedProduct[ii].goodsEn;
                obj.categoryId = vm.checkedProduct[ii].categoryId;
                obj.brandId = vm.checkedProduct[ii].brandId;
                obj.goodsPic = vm.checkedProduct[ii].goodsPic;
                obj.brandName = vm.checkedProduct[ii].brandName;
                obj.quantity = vm.checkedProduct[ii].quantity;
                vm.combination.goodsInfoList.push(obj);
              }
            }

        }
      },

      //删除产品
      deleteComfrim:function(index){
        let vm= this;
        vm.$confirm('此操作将删除此商品, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          vm.deleteProduct(index);
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        })
      },

      //删除产品
      deleteProduct:function(index){
        let vm = this;
        vm.combination.goodsInfoList.splice(index,1);
      },

      //定时信息提示
      setTime: function () {
        let vm = this;
        setTimeout(function () {
          vm.errorShow = false;
        }, 2500)
      },

      //关闭信息提示
      closeError:function(){
        this.errorShow = false;
      },

      //全选
      checkAllProduct:function(){
        let vm = this;
        if(!vm.allProduct){
          vm.checkedProduct = [];
          vm.show = false;
        }else {
          vm.checkedProduct = [];
          vm.show = true;
          vm.productList.forEach(function (item) {
            vm.checkedProduct.push(item)
          })
        }
      },

      //删除图片
      deletePicConfirm:function(){
        let vm = this;
        vm.$confirm('此操作将删除此图片, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          vm.deletePic();
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        })
      },

      //删除图片
      deletePic:function(){
        this.picShow = true;
        $('#file-upload').val('');
        this.combination.goodsPic = '';
      },

      //保存
      submitProduct:function(){
        let vm = this;
        for (let i = 0; i < vm.combination.goodsInfoList.length; i++){
          if(!vm.combination.goodsInfoList[i].quantity){
            // this.errorClass = false;
            // this.errorShow = true;
            // this.errorTitle = "操作失败";
            // this.errorMsg = "组合信息的商品单位数量为空！";
            // this.setTime();
            this.$message.error('组合信息的商品单位数量为空');
            return;
          }
        }
        console.log(vm.combination)
        instance({
          method:'post',
          url:'v1/goods/combination/addOrEdit',
          data:vm.combination
        }).then(function (data) {
          console.log(data)
          if(data.data.success){
            if(vm.combination.sku && vm.combination.goodsCn && vm.combination.goodsEn){
              vm.$router.push({
                path: "/v1/goods/combination/getList",
              })
            }
          }else {
            // vm.errorClass = false;
            // vm.errorShow = true;
            // vm.errorTitle = "操作失败";
            // vm.errorMsg = data.data.msg;
            vm.$message.error(data.data.msg);
            // vm.setTime();
          }
        })
      },

      //获取品牌分类
      getBrandList:function(){
        let vm = this;
        instance({
          method:'post',
          url:'v1/goods/brand/getList',
        }).then(function (data) {
          if(data.data.success){
            vm.brandList = data.data.data;
          }
        })
      },

      getMenuName: function (menus) {
        let vm = this;
        for (var value of menus) {
          if (value.categoryId == vm.combination.categoryId) {
            vm.formData.inspectObjectName = value.categoryName;
            console.log('value.categoryName',value.categoryName)
          }
          if (value.children) {
            this.getMenuName(value.children)
          }
        }
      },

      //获取路由传参
      getItem:function () {
        let vm = this;
        let routerParams = this.$route.query.id;
        let readonly = this.$route.query.readonly;
        instance({
          method:'post',
          url:'v1/goods/combination/queryDetail',
          params:{
            id:routerParams
          }
        }).then(function (data) {
          console.log(data)
          if(data.data.success){
            vm.readonly = readonly;
            vm.picShow = false;
            vm.combination = data.data.data[0];
            vm.getMenuName(vm.allCategoryAnalysis);
            vm.combination.id = routerParams;

          }
        })
      },

      //图片上传
      fileClick: function () {
        if(!this.combination.sku){
          // this.errorClass = false;
          // this.errorShow = true;
          // this.errorTitle = "上传图片错误";
          // this.errorMsg = "请填写组合SKU";
          // this.setTime();
          this.$message.error('请填写组合SKU');
        }
        if(this.combination.sku && !this.readonly){
          document.getElementById("file-upload").click();
        }


      },
      choosePic: function (e) {
        let vm = this;
        let current_pic = e.target.files[0];
        this.show = false;
        let form = new FormData();
        form.append('file',current_pic,current_pic.name);
        form.append("key", vm.combination.sku);
        form.append("type", "goods");
        // let config = {
        //   headers: {'Content-Type': 'multipart/form-data'}
        // }
        // instance.post('/v1/goods/uploadPic',form,config).then(data =>{
        //   console.log(data)
        //   if (data.data.success){
        //     vm.combination.goodsPic = data.data.data;
        //     vm.picShow = false;
        //     vm.$message({
        //       message: '上传图片成功！',
        //       type: 'success'
        //     });
        //   }
        // })
        axios({
          method: 'post',
          url: baseURL + '/v1/goods/uploadPic',
          headers: {
            'Content-Type': 'multipart/form-data'
          },
          data: form
        }).then(function (data) {
          if (data.data.success){
            if (data.data.code == '9999') {
              vm.$router.push({
                path: '/login',
              });
              return
            }
            if ( data.data.code == '0000') {
              vm.$router.push({
                path: '/401',
              });
              return
            }
            if ( data.data.code == '1111') {
              vm.$router.push({
                path: '/401',
              });
              return
            }
            vm.combination.goodsPic = data.data.data;
            vm.picShow = false;
            vm.$message({
              message: '上传图片成功！',
              type: 'success'
            });
          }
        });
      },
    },
    created() {
      //获取商品分类
      this.getAllCategory();

      //获取品牌分类
      this.getBrandList();

      //获取路由传参
      this.getItem();
    },
    components:{
      pagination
    },
    computed:{
      sku(){
        return this.combination.sku;
      },
      goodsCn(){
        return this.combination.goodsCn;
      },
      goodsEn(){
        return this.combination.goodsEn;
      },
    },
    watch:{
      allMenu:function(val){
        let vm = this;
        console.log(val)
        if(val && vm.combination[0]){
          for (let i = 0; i < val.length; i++){
            if(val[i].categoryId == vm.combination[0].categoryId){
              vm.formData.inspectObjectName = val[i].categoryName;
            }
          }
        }
        // for (let i = 0; i < val.length; i++){
        //   if(val[i].categoryId == vm.combination.categoryId){
        //     vm.formData.inspectObjectName = val[i].categoryName;
        //   }
        // }
      },
      sku:function () {
        this.combination.sku = this.combination.sku.replace(/[^A-Za-z0-9\-\_\.]/g,'');
        if(this.combination.sku.length > 51){
          this.combination.sku = this.combination.sku.substr(0,51)
        }
      },
      goodsCn:function () {
        // this.combination.goodsCn = this.combination.goodsCn.replace(/[^\a-\z\A-\Z0-9\-\.\*\&\^\%\$\￥\(\)\（\）\#\+\@\!\_\<\>\?\\\/\[\]\:\;\'\"\,\=\`\~]/g,'');
      },
      goodsEn:function () {
        this.combination.goodsEn = this.combination.goodsEn.replace(/[^\a-\z\A-\Z0-9\-\.\*\&\^\%\$\￥\(\)\（\）\#\+\@\!\_\<\>\?\\\/\[\]\:\;\'\"\,\=\`\~]/g,'');
      },
    }
  }
</script>

<style scoped>
  .objectTree {
    position: absolute!important;
    overflow: auto;
    z-index: 100;
    width: 100%;
    height: 300px;
    border: 1px solid #cccdce;
    border-top: none;
  }
  .linehe  input{
    height: 34px!important;
    line-height: 34px!important;
  }
  .el-select-dropdown__item{
    line-height: 24px!important;
    height: 24px!important;
  }
  .el-select-dropdown__item span{
    line-height: 24px!important;
  }
  .el-input.is-disabled .el-input__inner{
    background-color: #eeeeee;
    color: #555;
  }
  .treeSelect{
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right:0;
    z-index: 99;
    background: rgba(255,255,255,0);
  }
</style>
